package com.stagewebserver.webserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stagewebserver.webserver.mapper.AuthorMapper;
import com.stagecommon.common.pojo.Author;
import com.stagecommon.common.pojo.RespBean;
import com.stagewebserver.webserver.service.AuthorService;
import com.stagecommon.common.vo.AuthorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: yxl
 * @since: 2021-11-22
 **/
@Service
public class AuthorServiceImpl extends ServiceImpl<AuthorMapper, Author> implements AuthorService {

    @Autowired
    private AuthorMapper authorMapper;

    @Override
    public RespBean getRecommendAuthors() {
        return RespBean.operationSuccess("推荐成功",200,authorMapper.selectRecommendAuthors());
    }

    @Override
    public RespBean<List<AuthorVo>> selectAuthorsByKeyword(String keyword) {
        return RespBean.operationSuccess("查询成功",200,authorMapper.selectAuthorsByKeyword(keyword));
    }

    @Override
    public RespBean<List<AuthorVo>> selectAllAuthors() {
        return RespBean.operationSuccess("查询成功",200,authorMapper.selectAllAuthors());
    }

    @Override
    public RespBean<Author> selectAuthorByUsername(Author author) {
        return RespBean.operationSuccess("查询成功", 200, authorMapper.selectAuthorByUsername(author.getUsername()));
    }

    @Override
    public RespBean<Author> selectAuthorById(Author author) {
        return RespBean.operationSuccess("查询成功",200,authorMapper.selectOne(new QueryWrapper<Author>().select("user_id","username","introduction","author_img").eq("user_id",author.getUserId())));
    }
}
